package com.oniontech.stamptour.common.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.oniontech.stamptour.ApplicationManager;
import com.oniontech.stamptour.R;
import com.oniontech.stamptour.common.adapter.Bean.ContentsListBean;

import java.util.List;

/**
 * Created by Administrator on 14. 1. 23.
 */
public class StampContListAdapter extends BaseAdapter {
    private List<ContentsListBean> contentsListBean = null;
    private LayoutInflater inflater = null;
    private Context context = null;
    private ViewHolder viewHolder = null;
    private ImageLoader imageLoader = null;
    private String visitOk = "#00545e";
    private String visitNo = "#464747";

    public StampContListAdapter(List<ContentsListBean> contentsBeanList) {
        this.contentsListBean = contentsBeanList;
        this.context = ApplicationManager.getInstance();
        this.inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.imageLoader = ImageLoader.getInstance();
    }

    @Override
    public int getCount() {
        return contentsListBean != null ? contentsListBean.size() : 0;
    }

    @Override
    public ContentsListBean getItem(int i) {
        return contentsListBean.get(i);
    }

    @Override
    public long getItemId(int i) {
        return contentsListBean.get(i).hashCode();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ContentsListBean data = getItem(i);

        if (view == null) {
            view = inflater.inflate(R.layout.main_to_list_row, null);
            viewHolder = new ViewHolder();
            viewHolder.thumb = (ImageView) view.findViewById(R.id.thumb);
            viewHolder.thumbFrame = (ImageView) view.findViewById(R.id.thumbFrame);
            viewHolder.checkVisit = (ImageView) view.findViewById(R.id.checkVisit);
            viewHolder.title = (TextView) view.findViewById(R.id.title);

            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        imageLoader.displayImage("assets://img/" + data.getImg(), viewHolder.thumb);
        imageLoader.displayImage("assets://img/" + data.getListFrameImg(), viewHolder.thumbFrame);
        imageLoader.displayImage("assets://img/" + data.getListVisitImg(), viewHolder.checkVisit);
        viewHolder.title.setText(data.getName());
        if(data.getVisit() != 0) {
            viewHolder.title.setTextColor(Color.parseColor(visitOk));
        } else {
            viewHolder.title.setTextColor(Color.parseColor(visitNo));
        }
        return view;
    }

    private class ViewHolder {
        public ImageView thumb = null;
        public ImageView thumbFrame = null;
        public ImageView checkVisit = null;
        public TextView title = null;
    }
}
